// 测试密码加密功能
const bcrypt = require('bcrypt');

async function testPasswordEncryption() {
  try {
    // 测试密码
    const plainPassword = 'test123456';
    
    // 加密密码
    const saltRounds = 10;
    const hashedPassword = await bcrypt.hash(plainPassword, saltRounds);
    
    console.log('原始密码:', plainPassword);
    console.log('加密后密码:', hashedPassword);
    
    // 验证密码
    const isMatch = await bcrypt.compare(plainPassword, hashedPassword);
    console.log('密码验证结果:', isMatch ? '成功' : '失败');
    
    // 测试错误密码
    const wrongPassword = 'wrongpassword';
    const isMatchWrong = await bcrypt.compare(wrongPassword, hashedPassword);
    console.log('错误密码验证结果:', isMatchWrong ? '成功' : '失败');
    
  } catch (error) {
    console.error('测试过程中出错:', error);
  }
}

testPasswordEncryption();